home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / showch.c < prev    next >
Text File  |  1985-12-29  |  2KB  |  59 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ showch - display a character on the screen.        */
  4. /*@        The character is displayed normally, if     */
  5. /*@        possible, displayed as a reverse video      */
  6. /*@        name (e.g. NUL for 0x00), if appropriate,   */
  7. /*@        or displayed as \xxx\ where xxx is the      */
  8. /*@        decimal value of the character.             */
  9. /*@                                                    */
  10. /*@   Usage:     showch(ch);                           */
  11. /*@       where ch is a character.                     */
  12. /*@                                                    */
  13. /*@   Returns the number of screen positions used to   */
  14. /*@       display the character.                       */
  15. /*@                                                    */
  16. /*@*****************************************************/
  17.  
  18. #define EOS '\0'
  19. #define     REVVID  0x70    /* reverse video attribute */
  20. #define     NORM    0x07    /* normal video attribute */
  21.  
  22. int
  23. showch(c)
  24. char c;
  25. {
  26.     static char *cntlchr[] = {"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL",
  27.         "BS ","HT ","LF ","VT ","FF ","CR ","SO ","SI ","DLE",
  28.         "DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM ",
  29.         "SUB","ESC","FS ","GS ","RS ","US "};
  30.  
  31.     int ret, strbuf[4];
  32.     ret = 0;
  33.  
  34.     if ((c >= 0) && (c <= 31)) {   /* HANDLE CONTROL CHARS */
  35.         ret = 3;   /* number of positions used */
  36.         conout(cntlchr[(int)c],REVVID);
  37.     }
  38.     else if ((c >= ' ') && (c <= '~')) { /* HANDLE NORMAL CHARS */
  39.         ret = 1;  /* number of positions used */
  40.         strbuf[0] = c;        /* display as normal video */
  41.         strbuf[1] = EOS;
  42.         conout(strbuf,NORM);
  43.     }
  44.     else if (c == 127) {        /* HANDLE 0X7F (DEL) */
  45.         ret = 3;   /* number of positions used */
  46.         conout("DEL",REVVID);
  47.     }
  48.     else {                /* HANDLE FUNNY CHARS */
  49.         conout("\\",REVVID);
  50.         itoa(c,strbuf);
  51.         conout(strbuf,REVVID);
  52.         conout("\\",REVVID);
  53.         ret = strlen(strbuf) + 2;  /* number of positions used */
  54.     }
  55.     conout(" ",NORM);         /* separate displays */
  56.     return(++ret);
  57. }
  58.  
  59.